<html>
<head><meta charset="utf-8"><title>reuse visitor for const patterns · t-compiler/const-eval · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/index.html">t-compiler/const-eval</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/reuse.20visitor.20for.20const.20patterns.html">reuse visitor for const patterns</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="147656973"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/reuse%20visitor%20for%20const%20patterns/near/147656973" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/reuse.20visitor.20for.20const.20patterns.html#147656973">(Nov 14 2018 at 09:41)</a>:</h4>
<p>We convert <code>const</code> items used in patterns into full patterns by expanding e.g. a use of <code>const FOO: (u32, u32) = (5, 6);</code> as a <code>FOO</code> pattern into a tuple pattern of constants like <code>(5, 6)</code>. This is main user of <code>const_field</code> and <code>const_downcast</code>. I have started looking into cleaning this up. There's significant overlap with <code>Visitor</code>, but I don't really know how to use the <code>Visitor</code>s for that use case. What I basically want is to not mutate a value in place by visiting it, I want to convert it to a completely different type</p>



<a name="147657052"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/reuse%20visitor%20for%20const%20patterns/near/147657052" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/reuse.20visitor.20for.20const.20patterns.html#147657052">(Nov 14 2018 at 09:43)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> do you think these use cases are different enough to warrant a parallel but similar setup? Or should I try to make the Visitors support my use case?</p>



<a name="147657172"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/reuse%20visitor%20for%20const%20patterns/near/147657172" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/reuse.20visitor.20for.20const.20patterns.html#147657172">(Nov 14 2018 at 09:45)</a>:</h4>
<blockquote>
<p>main user of const_field and const_downcast</p>
</blockquote>
<p>main or only? :D</p>



<a name="147657308"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/reuse%20visitor%20for%20const%20patterns/near/147657308" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/reuse.20visitor.20for.20const.20patterns.html#147657308">(Nov 14 2018 at 09:48)</a>:</h4>
<blockquote>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> do you think these use cases are different enough to warrant a parallel but similar setup? Or should I try to make the Visitors support my use case?</p>
</blockquote>
<p>I suppose this depends on how much of a change this would require to the visitor, how big the complexity cost is there. I suppose what you want is a thing where the <code>visit</code> methods actually <em>return</em> something? Turning them from <code>visit</code> more into a <code>map_and_fold</code>? I feel this should be possible to add without too much additional complexity, where the default visitor uses <code>()</code> as return type.</p>



<a name="147657344"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/reuse%20visitor%20for%20const%20patterns/near/147657344" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/reuse.20visitor.20for.20const.20patterns.html#147657344">(Nov 14 2018 at 09:49)</a>:</h4>
<p>main user, but the other one can be solved, too I think. The other user is some simd stuff during mir construction</p>



<a name="147657415"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/reuse%20visitor%20for%20const%20patterns/near/147657415" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/reuse.20visitor.20for.20const.20patterns.html#147657415">(Nov 14 2018 at 09:50)</a>:</h4>
<p>Yea, I think the return value change should totally suffice and not affect the regular visitor uses at all.</p>



<a name="147658105"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/reuse%20visitor%20for%20const%20patterns/near/147658105" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/reuse.20visitor.20for.20const.20patterns.html#147658105">(Nov 14 2018 at 10:05)</a>:</h4>
<p>well there will likely have to be a folding method somewhere for which we cannot have a default impl. but the visitor implementation would trivially return <code>()</code>. or maybe I am wrong and we have enough wrappers for that already.</p>



<a name="147658111"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/reuse%20visitor%20for%20const%20patterns/near/147658111" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/reuse.20visitor.20for.20const.20patterns.html#147658111">(Nov 14 2018 at 10:05)</a>:</h4>
<p>So yeah, generalizing from a visitor to a map-fold is fine for me</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>